﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using npcook.Terminal;
using npcook.Terminal.Controls;
using System.IO;
using Renci.SshNet;

namespace FastShell.Common
{
    public class ShellStreamNotifier : IStreamNotifier
    {
        TerminalControl terminal;

        public Stream Stream
        { get; set; }

        public event EventHandler DataAvailable;

        public ShellStreamNotifier(TerminalControl terminal, ShellStream stream)
        {
            this.terminal = terminal;
            Stream = stream;
            stream.DataReceived += Stream_DataReceived;
        }

        private void Stream_DataReceived(object sender, Renci.SshNet.Common.ShellDataEventArgs e)
        {
            terminal.BeginChange();
            if (DataAvailable != null)
                DataAvailable(this, EventArgs.Empty);
            terminal.EndChange();
        }
    }
}
